using System.Collections.Generic;
using System.Collections.ObjectModel;
using CodePlex.DnD4eCampaignManager.CampaignManagerTests.TestUtilities;
using CodePlex.DnD4eCampaignManager.DnD4e.Interfaces;
using CodePlex.DnD4eCampaignManager.Presentation;
using CodePlex.DnD4eCampaignManager.Presentation.ViewInterfaces;
using CodePlex.DnD4eCampaignManager.Repositories.Interfaces;
using NUnit.Framework;
using Rhino.Mocks;

namespace CodePlex.DnD4eCampaignManager.CampaignManagerTests.PresentationTests
{
    [TestFixture]
    public class PlayerCharacterPresenterTests
    {
        private IPlayerCharacter _playerCharacter;
        private ReadOnlyCollection<string> _playerCharacterNames;
        private IPlayerCharacterRepository _playerCharacterRepository;
        private PlayerCharacterPresenter _presenter;
        private IPlayerCharacterView _view;
        private PlayerCharacterPresenterTestHelpers PlayerCharacterPresenterTestHelpers { get; set; }

        //Expect.Call(PlayerCharacterRepository.GetByName(PlayerCharacterPresenterTestHelpers.PLAYER_CHARACTER_NAME)).Return(playerCharacter);
        //PlayerCharacterPresenterTestHelpers.PullBasicDataFromView(Mocks);
        //PlayerCharacterPresenterTestHelpers.PullAbilitiesFromView(Mocks);
        //PlayerCharacterPresenterTestHelpers.PullDefensesFromView(Mocks);
        //PlayerCharacterPresenterTestHelpers.PullHitPointsFromView(Mocks);
        //PlayerCharacterPresenterTestHelpers.PullSurgesFromView(Mocks);
        //PlayerCharacterPresenterTestHelpers.PullInitiativeFromView(Mocks);
        //PlayerCharacterPresenterTestHelpers.PullMovementFromView(Mocks);
        //PlayerCharacterPresenterTestHelpers.PullSensesFromView(Mocks);
        //PlayerCharacterPresenterTestHelpers.PullPowersFromView(Mocks);

        //PlayerCharacterPresenterTestHelpers.BasicAssertions(playerCharacter);
        //PlayerCharacterPresenterTestHelpers.AbilityAssertions(playerCharacter);
        //PlayerCharacterPresenterTestHelpers.DefensesAssertions(playerCharacter);

        [Test]
        public void DisplayPlayerCharacterPopulatesTheViewFromThePlayerCharacterRepository()
        {
//            PlayerCharacterRepository = Mocks.StrictMock<IPlayerCharacterRepository>();
//            PlayerCharacterView = Mocks.StrictMock<IPlayerCharacterView>();
//            IPlayerCharacter playerCharacter = DefaultTestObjects.TestPlayerCharacter();
//            ReadOnlyCollection<string> _playerCharacterNames =
//                new List<string> { PlayerCharacterPresenterTestHelpers.PLAYER_CHARACTER_NAME }.AsReadOnly();
//            PlayerCharacterPresenterTestHelpers = new PlayerCharacterPresenterTestHelpers(PlayerCharacterView);
//            using ( Mocks.Record() )
//            {
//                Expect.Call(PlayerCharacterRepository.GetByName(PlayerCharacterPresenterTestHelpers.PLAYER_CHARACTER_NAME)).Return(playerCharacter);
//                PlayerCharacterView.CharacterName = PlayerCharacterPresenterTestHelpers.PLAYER_CHARACTER_NAME;
//                Expect.Call(PlayerCharacterRepository.GetAllNames()).Return(_playerCharacterNames);
//                Expect.Call(PlayerCharacterRepository.GetByName(PlayerCharacterPresenterTestHelpers.PLAYER_CHARACTER_NAME)).Return(playerCharacter);
//                PlayerCharacterPresenterTestHelpers.PushBasicDataToView(playerCharacter);
//                PlayerCharacterPresenterTestHelpers.PushMovementDataToView(playerCharacter);
//                PlayerCharacterPresenterTestHelpers.PushHealthDataToView(playerCharacter);
//                PlayerCharacterPresenterTestHelpers.PushSensesToView(playerCharacter);
//                PlayerCharacterPresenterTestHelpers.PushAbilitiesToView(playerCharacter);
//                PlayerCharacterPresenterTestHelpers.PushPowersToView(playerCharacter);
//                PlayerCharacterPresenterTestHelpers.PushDefensesToView(playerCharacter);
//                PlayerCharacterPresenterTestHelpers.PushSkillsToView(playerCharacter);
//            }
//            using ( Mocks.Playback() )
//            {
//                PlayerCharacterPresenter presenter = new PlayerCharacterPresenter(PlayerCharacterPresenterTestHelpers.PLAYER_CHARACTER_NAME,
//                                                                                  PlayerCharacterView, PlayerCharacterRepository);
//                presenter.DisplayPlayerCharacter();
//            }
        }

        [Test]
        public void DisplayPlayerCharacterPushesThePlayerCharacterAbilitiesToTheView()
        {
            _playerCharacterRepository.Stub(x => x.GetAllNames()).Return(_playerCharacterNames);
            _playerCharacterRepository.Stub(x => x.GetByName(_playerCharacter.Name)).Return(_playerCharacter);
            _view.Expect(x => x.AbilityStrength = _playerCharacter.AbilityStrength);
            _view.Expect(x => x.AbilityConstitution = _playerCharacter.AbilityConstitution);
            _view.Expect(x => x.AbilityDexterity = _playerCharacter.AbilityDexterity);
            _view.Expect(x => x.AbilityIntelligence = _playerCharacter.AbilityIntelligence);
            _view.Expect(x => x.AbilityWisdom = _playerCharacter.AbilityWisdom);
            _view.Expect(x => x.AbilityCharisma = _playerCharacter.AbilityCharisma);
            _presenter.DisplayPlayerCharacter();
        }

        [Test]
        public void DisplayPlayerCharacterPushesThePlayerCharacterBasicCharacterDataToTheView()
        {
            _playerCharacterRepository.Stub(x => x.GetAllNames()).Return(_playerCharacterNames);
            _playerCharacterRepository.Stub(x => x.GetByName(_playerCharacter.Name)).Return(_playerCharacter);
            _view.Expect(x => x.CharacterName = _playerCharacter.Name);
            _view.Expect(x => x.CharacterLevel = _playerCharacter.CharacterLevel);
            _view.Expect(x => x.CharacterClass = _playerCharacter.CharacterClass);
            _view.Expect(x => x.CharacterParagonPath = _playerCharacter.CharacterParagonPath);
            _view.Expect(x => x.CharacterEpicDestiny = _playerCharacter.CharacterEpicDestiny);
            _view.Expect(x => x.CharacterExperiencePoints = _playerCharacter.CharacterExperiencePoints);
            _view.Expect(x => x.CharacterRace = _playerCharacter.CharacterRace);
            _view.Expect(x => x.CreatureSize = _playerCharacter.CreatureSize);
            _view.Expect(x => x.CharacterAge = _playerCharacter.CharacterAge);
            _view.Expect(x => x.CharacterGender = _playerCharacter.CharacterGender);
            _view.Expect(x => x.CharacterHeight = _playerCharacter.CharacterHeight);
            _view.Expect(x => x.CharacterWeight = _playerCharacter.CharacterWeight);
            _presenter.DisplayPlayerCharacter();
        }

        [Test]
        public void DisplayPlayerCharacterPushesThePlayerCharacterDefensesToTheView()
        {
            _playerCharacterRepository.Stub(x => x.GetAllNames()).Return(_playerCharacterNames);
            _playerCharacterRepository.Stub(x => x.GetByName(_playerCharacter.Name)).Return(_playerCharacter);
            _view.Expect(x => x.DefenseArmorClass = _playerCharacter.DefenseArmorClass);
            _view.Expect(x => x.DefenseFortitude = _playerCharacter.DefenseFortitude);
            _view.Expect(x => x.DefenseReflex = _playerCharacter.DefenseReflex);
            _view.Expect(x => x.DefenseWillpower = _playerCharacter.DefenseWillpower);
            _presenter.DisplayPlayerCharacter();
        }

        [Test]
        public void DisplayPlayerCharacterPushesThePlayerCharacterHealthToTheView()
        {
            _playerCharacterRepository.Stub(x => x.GetAllNames()).Return(_playerCharacterNames);
            _playerCharacterRepository.Stub(x => x.GetByName(_playerCharacter.Name)).Return(_playerCharacter);
            _view.Expect(x => x.HealingSurgesCurrent = _playerCharacter.HealingSurgesCurrent);
            _view.Expect(x => x.HealingSurgesMaximum = _playerCharacter.HealingSurgesMaximum);
            _view.Expect(x => x.HealingSurgeValue = _playerCharacter.HealingSurgeValue);
            _view.Expect(x => x.HitPointsCurrent = _playerCharacter.HitPointsCurrent);
            _view.Expect(x => x.HitPointsMaximum = _playerCharacter.HitPointsMaximum);
            _view.Expect(x => x.HitPointsTemporary = _playerCharacter.HitPointsTemporary);
            _presenter.DisplayPlayerCharacter();
        }

        [Test]
        public void DisplayPlayerCharacterRetrievesThePlayerCharacterSpecifiedInTheConstructorFromThePlayerCharacterRepository()
        {
            _playerCharacterRepository.Stub(x => x.GetAllNames()).Return(_playerCharacterNames);
            _playerCharacterRepository.Expect(x => x.GetByName(_playerCharacter.Name)).Return(_playerCharacter);
            _presenter.DisplayPlayerCharacter();
        }

        [SetUp]
        public void SetUp()
        {
            _view = MockRepository.GenerateMock<IPlayerCharacterView>();
            _playerCharacterRepository = MockRepository.GenerateMock<IPlayerCharacterRepository>();
            _playerCharacter = DefaultTestObjects.TestPlayerCharacter();
            _presenter = new PlayerCharacterPresenter(_playerCharacter.Name, _view, _playerCharacterRepository);
            _playerCharacterNames = new List<string> { _playerCharacter.Name }.AsReadOnly();
        }

        [TearDown]
        public void TearDown()
        {
            _view.VerifyAllExpectations();
            _playerCharacterRepository.VerifyAllExpectations();
        }
    }
}